<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .main {
            width: 800px;
            margin: 50px auto;
        }

        #wrap {
            width: 800px;
            height: 500px;
            border: solid 1px red;
            position: relative;
            margin-top: 20px;
            margin-left: 100px;
        }

        #move {
            width: 100px;
            height: 100px;
            background-color: pink;
            /* 设置成圆球 */
            border-radius: 50%;
            position: absolute;
        }
    </style>
</head>

<body>
    <div class="main">
        <button id="left-btn">向左走</button>
        <button id="right-btn">向右走</button>
    </div>
    <div id="wrap">
        <div id="move"></div>
    </div>
</body>
<script>
    var leftBtn = document.getElementById('left-btn');
    var rightBtn = document.getElementById('right-btn');
    var move = document.getElementById('move');
    var wrap = document.getElementById('wrap');
    var interid;
    rightBtn.onclick = function (e) {
        move.interid = setInterval(
            function () {
                if (move.offsetLeft >= 700) {
                    clearInterval(move.interid)
                } else {
                    var step = (1 + move.offsetLeft)
                    move.style.left = move.offsetLeft + step + 'px';
                    console.log(step)
                }
            }, 30
        )
    }
</script>

</html>